﻿/*----------------------------------------------------------------
// Copyright (C) 2011 周士祎
// 版权所有。 
//
// 文件名：CanteenReportsController
// 文件功能描述：食堂报表
//
// 
// 创建标识：2012-02-20 周士祎
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.Mvc;
using Model.WaiGaoQiao;
using WaiGaoQiaoWeb.Models;
using WaiGaoQiaoWeb.JsonEntities;

namespace WaiGaoQiaoWeb.Controllers
{
    public class CanteenReportsController : Controller
    {
        //
        // GET: /CanteenReports/
        private OutstockSporadicInfo outstocksporadic = new OutstockSporadicInfo(true);
        public ActionResult OutSporadicIndex()
        {
            ViewData["yy"] = GetOutstockYY();
            ViewData["mm"] = GetOutstockMM();
            ViewData["canteen"] = GetYaxNode();
            return View();
        }

        /// <summary>
        /// 获取年份列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetOutstockYY()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, (DateTime.Now.Date.Year - 1).ToString());
            dic.Add(2, (DateTime.Now.Date.Year).ToString());
            dic.Add(3, (DateTime.Now.Date.Year + 1).ToString());
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem()
                {
                    Text = m.Value.ToString(),
                    Value = m.Key.ToString(),
                    Selected = (m.Value == (DateTime.Now.Date.Year).ToString()) ? true : false
                }).ToList();
            return selectList;
        }
        /// <summary>
        /// 获取月份列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetOutstockMM()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, "1");
            dic.Add(2, "2");
            dic.Add(3, "3");
            dic.Add(4, "4");
            dic.Add(5, "5");
            dic.Add(6, "6");
            dic.Add(7, "7");
            dic.Add(8, "8");
            dic.Add(9, "9");
            dic.Add(10, "10");
            dic.Add(11, "11");
            dic.Add(12, "12");
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem()
                {
                    Text = m.Value.ToString(),
                    Value = m.Key.ToString(),
                    Selected = (m.Value == DateTime.Now.Month.ToString()) ? true : false
                }).ToList();
            return selectList;
        }

        public ActionResult BuliderReportOutSporadic(PageVM pvm)
        {
            string condition = pvm.query;
            int yy = Convert.ToInt32(condition.Split(',')[0]);
            int mm = Convert.ToInt32(condition.Split(',')[1]);
            string st = condition.Split(',')[2].ToString();
            JsonFlexiGridData jsonFlexiGridData = new JsonFlexiGridData();
            jsonFlexiGridData.page = pvm.page;
            jsonFlexiGridData.total = outstocksporadic.GetOutstockGroupCountBb("and PriorID = (select con.ID from Con_Goods con where con.GoodsName = '零星物品')");

            DataSet list = outstocksporadic.BuilderReportLy(yy, mm, st, pvm.rp, pvm.page);

            List<string> v;
            foreach (DataRow item in list.Tables[0].Rows)
            {
                #region
                v = new List<string>();
                v.Add(item[1].ToString());
                v.Add(item[2].ToString());
                v.Add(item[3].ToString());
                v.Add(item[4].ToString());
                v.Add(item[5].ToString());
                v.Add(item[6].ToString());
                v.Add(item[7].ToString());
                v.Add(item[8].ToString());
                v.Add(item[9].ToString());
                v.Add(item[10].ToString());
                v.Add(item[11].ToString());
                v.Add(item[12].ToString());
                v.Add(item[13].ToString());
                v.Add(item[14].ToString());
                v.Add(item[15].ToString());
                v.Add(item[16].ToString());
                v.Add(item[17].ToString());
                v.Add(item[18].ToString());
                v.Add(item[19].ToString());
                v.Add(item[20].ToString());
                v.Add(item[21].ToString());
                v.Add(item[22].ToString());
                v.Add(item[23].ToString());
                v.Add(item[24].ToString());
                v.Add(item[25].ToString());
                v.Add(item[26].ToString());
                v.Add(item[27].ToString());
                v.Add(item[28].ToString());
                v.Add(item[29].ToString());
                v.Add(item[30].ToString());
                v.Add(item[31].ToString());
                v.Add(item[32].ToString());
                v.Add(item[33].ToString());
                v.Add(item[34].ToString());
                v.Add(item[35].ToString());
                #endregion
                FlexiGridRow fgr = new FlexiGridRow()
                {
                    id = item[1].ToString(),
                    cell = v
                };
                jsonFlexiGridData.rows.Add(fgr);
            }
            return Json(jsonFlexiGridData);
        }
        /// <summary>
        /// 食堂零星物品领用表
        /// </summary>
        /// <returns></returns>
        public ActionResult OutstockSporadic(int yy, int mm, string st)
        {
            return EContent(yy, mm, st);
        }
        public ExcelContentResult EContent(int yy, int mm, string st)
        {
            StringBuilder sBuilder = new StringBuilder();
            int totlerows = outstocksporadic.GetSportadicOutCount("");// GetOutstockGroupSundriesCount("");
            DataSet list = outstocksporadic.BuilderReportLy(yy, mm, st, totlerows, 1);
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr style=' white-space: nowrap;'>");
            sBuilder.Append("<td colspan='33' style='font-size:25px; text-align:center;'>食堂零星物品领用表</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style=' white-space: nowrap;'>");
            sBuilder.Append("<td colspan='33' style=' font-size:17px; text-align:center;'>"
                + yy.ToString() + "-" + mm.ToString() + "月份</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style=' white-space: nowrap;font-size:17px;'>");
            //sBuilder.Append("<td>ID</td>");
            //sBuilder.Append("<td>零星物品编号</td>");
            sBuilder.Append("<td>零星物品名称</td>");
            sBuilder.Append("<td>1</td>");
            sBuilder.Append("<td>2</td>");
            sBuilder.Append("<td>3</td>");
            sBuilder.Append("<td>4</td>");
            sBuilder.Append("<td>5</td>");
            sBuilder.Append("<td>6</td>");
            sBuilder.Append("<td>7</td>");
            sBuilder.Append("<td>8</td>");
            sBuilder.Append("<td>9</td>");
            sBuilder.Append("<td>10</td>");
            sBuilder.Append("<td>11</td>");
            sBuilder.Append("<td>12</td>");
            sBuilder.Append("<td>13</td>");
            sBuilder.Append("<td>14</td>");
            sBuilder.Append("<td>15</td>");
            sBuilder.Append("<td>16</td>");
            sBuilder.Append("<td>17</td>");
            sBuilder.Append("<td>18</td>");
            sBuilder.Append("<td>19</td>");
            sBuilder.Append("<td>20</td>");
            sBuilder.Append("<td>21</td>");
            sBuilder.Append("<td>22</td>");
            sBuilder.Append("<td>23</td>");
            sBuilder.Append("<td>24</td>");
            sBuilder.Append("<td>25</td>");
            sBuilder.Append("<td>26</td>");
            sBuilder.Append("<td>27</td>");
            sBuilder.Append("<td>28</td>");
            sBuilder.Append("<td>29</td>");
            sBuilder.Append("<td>30</td>");
            sBuilder.Append("<td>31</td>");
            sBuilder.Append("<td>合计</td>");
            sBuilder.Append("</tr>"); //style='vnd.ms-excel.numberformat:@'
            foreach (DataRow item in list.Tables[0].Rows)
            {
                sBuilder.Append("<tr style='font-size:14px; white-space: nowrap;'>");
                ////sBuilder.Append("<td>"+item[0].ToString()+"</td>");
                //sBuilder.Append("<td>" + item[1].ToString() + "</td>");
                //sBuilder.Append("<td>" + item[2].ToString() + "</td>");
                sBuilder.Append("<td>" + item[3].ToString() + "</td>");
                sBuilder.Append("<td>" + item[4].ToString() + "</td>");
                sBuilder.Append("<td>" + item[5].ToString() + "</td>");
                sBuilder.Append("<td>" + item[6].ToString() + "</td>");
                sBuilder.Append("<td>" + item[7].ToString() + "</td>");
                sBuilder.Append("<td>" + item[8].ToString() + "</td>");
                sBuilder.Append("<td>" + item[9].ToString() + "</td>");
                sBuilder.Append("<td>" + item[10].ToString() + "</td>");
                sBuilder.Append("<td>" + item[11].ToString() + "</td>");
                sBuilder.Append("<td>" + item[12].ToString() + "</td>");
                sBuilder.Append("<td>" + item[13].ToString() + "</td>");
                sBuilder.Append("<td>" + item[14].ToString() + "</td>");
                sBuilder.Append("<td>" + item[15].ToString() + "</td>");
                sBuilder.Append("<td>" + item[16].ToString() + "</td>");
                sBuilder.Append("<td>" + item[17].ToString() + "</td>");
                sBuilder.Append("<td>" + item[18].ToString() + "</td>");
                sBuilder.Append("<td>" + item[19].ToString() + "</td>");
                sBuilder.Append("<td>" + item[20].ToString() + "</td>");
                sBuilder.Append("<td>" + item[21].ToString() + "</td>");
                sBuilder.Append("<td>" + item[22].ToString() + "</td>");
                sBuilder.Append("<td>" + item[23].ToString() + "</td>");
                sBuilder.Append("<td>" + item[24].ToString() + "</td>");
                sBuilder.Append("<td>" + item[25].ToString() + "</td>");
                sBuilder.Append("<td>" + item[26].ToString() + "</td>");
                sBuilder.Append("<td>" + item[27].ToString() + "</td>");
                sBuilder.Append("<td>" + item[28].ToString() + "</td>");
                sBuilder.Append("<td>" + item[29].ToString() + "</td>");
                sBuilder.Append("<td>" + item[30].ToString() + "</td>");
                sBuilder.Append("<td>" + item[31].ToString() + "</td>");
                sBuilder.Append("<td>" + item[32].ToString() + "</td>");
                sBuilder.Append("<td>" + item[33].ToString() + "</td>");
                sBuilder.Append("<td>" + item[34].ToString() + "</td>");
                sBuilder.Append("<td>" + item[35].ToString() + "</td>");
                sBuilder.Append("</tr>"); //style='vnd.ms-excel.numberformat:@'
            }
            sBuilder.Append("</table>");
            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "shicairuk";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }

        public ActionResult CostMaterialReport()
        {
            ViewData["yy"] = GetOutstockYY();
            ViewData["mm"] = GetOutstockMM();
            ViewData["GetGroup"] = GetGroup();
            ViewData["GetYaxNode"] = GetYaxNode();
            return View();
        }

        public ActionResult ExeportCostAccount(int gid, string dt)
        {
            ReportsInfo rinfo = new ReportsInfo();
            DataSet ds = rinfo.GetCostAccount(gid, dt);
            StringBuilder sBuilder = new StringBuilder();
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr>");
            sBuilder.Append("<td colspan='12' style='font-size:25px; text-align:center;'>食堂班组成本核算单</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;'>班组</td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;'></td>");
            sBuilder.Append("<td colspan='10' style='text-align:center; font-size:17px;'>" + dt + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td colspan='4' style='text-align:center; font-size:17px;'>主食品</td>");
            sBuilder.Append("<td colspan='4' style='text-align:center; font-size:17px;'>副食品</td>");
            sBuilder.Append("<td colspan='4' style='text-align:center; font-size:17px;'>调味品</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td>名 称</td>");
            sBuilder.Append("<td>数 量</td>");
            sBuilder.Append("<td>单 价</td>");
            sBuilder.Append("<td>金 额</td>");
            sBuilder.Append("<td>名 称</td>");
            sBuilder.Append("<td>数 量</td>");
            sBuilder.Append("<td>单 价</td>");
            sBuilder.Append("<td>金 额</td>");
            sBuilder.Append("<td>名 称</td>");
            sBuilder.Append("<td>数 量</td>");
            sBuilder.Append("<td>单 价</td>");
            sBuilder.Append("<td>金 额</td>");
            sBuilder.Append("</tr>");
            decimal zamount = 0.00M;
            decimal famount = 0.00M;
            decimal lamount = 0.00M;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                sBuilder.Append("<tr style='font-size:14px; white-space: nowrap;'>");
                sBuilder.Append("<td>" + item[2].ToString() + "</td>");
                sBuilder.Append("<td>" + item[3].ToString() + "</td>");
                sBuilder.Append("<td>" + item[4].ToString() + "</td>");
                sBuilder.Append("<td>" + item[5].ToString() + "</td>");
                sBuilder.Append("<td>" + item[7].ToString() + "</td>");
                sBuilder.Append("<td>" + item[8].ToString() + "</td>");
                sBuilder.Append("<td>" + item[9].ToString() + "</td>");
                sBuilder.Append("<td>" + item[10].ToString() + "</td>");
                sBuilder.Append("<td>" + item[12].ToString() + "</td>");
                sBuilder.Append("<td>" + item[13].ToString() + "</td>");
                sBuilder.Append("<td>" + item[14].ToString() + "</td>");
                sBuilder.Append("<td>" + item[15].ToString() + "</td>");
                sBuilder.Append("</tr>"); //style='vnd.ms-excel.numberformat:@'
                zamount += Convert.ToDecimal(item[5]);
                famount += Convert.ToDecimal(item[10]);
                lamount += Convert.ToDecimal(item[15]);
            }
            #region hang
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td colspan='3' style='text-align:center;'>主食品领用合计</td>");
            sBuilder.Append("<td style='text-align:center;'>" + zamount.ToString() + "</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center;'>副食品领用合计</td>");
            sBuilder.Append("<td style='text-align:center;'>" + famount.ToString() + "</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center;'>调味品领用合计</td>");
            sBuilder.Append("<td style='text-align:center;'>" + lamount.ToString() + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td colspan='4' style='text-align:center;'>本班回收金额</td>");
            sBuilder.Append("<td rowspan='2' style='text-align:center;'>接上班<br/>存货</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center;'>本班今天领用</td>");
            sBuilder.Append("<td rowspan='2' style='text-align:center;'>交下班<br/>存货</td>");
            sBuilder.Append("<td rowspan='9' colspan='3' style='text-align:center;'>备注</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td style='text-align:center;'>项目</td>");
            sBuilder.Append("<td style='text-align:center;'>次数</td>");
            sBuilder.Append("<td style='text-align:center;'>单价</td>");
            sBuilder.Append("<td style='text-align:center;'>金额</td>");
            sBuilder.Append("<td style='text-align:center;'>主食品</td>");
            sBuilder.Append("<td style='text-align:center;'>副食品</td>");
            sBuilder.Append("<td style='text-align:center;'>调味品</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td style='text-align:center;'>拉卡</td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][1].ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'></td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][0].ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'></td>");
            sBuilder.Append("<td style='text-align:center;'>" + zamount.ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'>" + famount.ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'>" + lamount.ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'></td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td style='text-align:center;'>外卖</td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][3].ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'></td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][2].ToString() + "</td>");
            sBuilder.Append("<td rowspan='2' colspan='3' style='text-align:center;'>支出合计金额</td>");
            sBuilder.Append("<td rowspan='2' colspan='2' style='text-align:center;'>" + (zamount + famount + lamount).ToString() + "</td>");
            sBuilder.Append("</tr>");

            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td style='text-align:center;'>招待券</td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][5].ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'></td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][4].ToString() + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td style='text-align:center;'>外理</td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][7].ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'></td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][6].ToString() + "</td>");
            sBuilder.Append("<td rowspan='2' colspan='2' style='text-align:center;'>本日盈亏</td>");
            sBuilder.Append("<td rowspan='2' colspan='3' style='text-align:center;'>" + (Convert.ToDecimal(ds.Tables[1].Rows[0][12]) - (zamount + famount + lamount)).ToString() + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td style='text-align:center;'>清单</td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][9].ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'></td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][8].ToString() + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td style='text-align:center;'>点心</td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][11].ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'></td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][10].ToString() + "</td>");
            sBuilder.Append("<td rowspan='2' style='text-align:center;'>累<br/>计</td>");
            sBuilder.Append("<td style='text-align:center;'>盈</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center;'>" + ds.Tables[2].Rows[0]["ying"].ToString() + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td colspan='3' style='text-align:center;'>回收合计金额</td>");
            sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[1].Rows[0][12].ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center;'>亏</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center;'>" + ds.Tables[2].Rows[0]["kui"].ToString() + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px;'>管理员</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px;'>发料</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px;'>复核</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px;'>领料人</td>");
            sBuilder.Append("</tr>");
            #endregion
            sBuilder.Append("</table>");
            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "CostAccount";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }

        /// <summary>
        /// 原料统计表
        /// </summary>
        /// <param name="yax"></param>
        /// <param name="yy"></param>
        /// <param name="mm"></param>
        /// <returns></returns>
        public ActionResult ExeprotMaterialTongJi(int yy, int mm, int yax)
        {
            ReportsInfo rep = new ReportsInfo();
            int rowcount = rep.GetProc_RawMaterialsAndStatisticsCount(yy, mm, yax);
            DataSet ds = rep.GetProc_RawMaterialsAndStatistics(yy, mm, yax, rowcount, 1);
            StringBuilder sBuilder = new StringBuilder();
            int iDayCount = DateTime.DaysInMonth(yy, mm - 1);
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr>");
            sBuilder.Append("<td colspan='100' style='font-size:25px; text-align:center;'>餐饮部原料统计表(第" + yax.ToString() + "食堂)</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr>");
            sBuilder.Append("<td colspan='100'>" + yy.ToString() + "年" + mm.ToString() + "月份</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr>");
            sBuilder.Append("<td rowspan='2' style='text-align:center; font-size:14px;'>项目1</td>");
            sBuilder.Append("<td rowspan='2' style='text-align:center; font-size:14px;'>项目2</td>");
            sBuilder.Append("<td rowspan='2' style='text-align:center; font-size:14px; '>项目3</td>");
            sBuilder.Append("<td rowspan='2' style='text-align:center; font-size:14px; '>品种</td>");
            for (int i = 21; i <= iDayCount; i++)
            {
                sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>" + i + "日</td>");
            }
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>1日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>2日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>3日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>4日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>5日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>6日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>7日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>8日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>9日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>10日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>11日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>12日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>13日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>14日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>15日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>16日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>17日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>18日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>19日</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:14px; '>20日</td>");
            sBuilder.Append("<td colspan='2' style='text-align:center; font-size:14px; '>每月合计</td>");
            sBuilder.Append("</tr>"); //style='vnd.ms-excel.numberformat:@'
            sBuilder.Append("<tr>");
            for (int i = 21; i <= iDayCount; i++)
            {
                sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
                sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
                sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            }
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '>金额</td>");
            sBuilder.Append("</tr>");
            decimal[] aday = new decimal[iDayCount];
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                int ni = 0;
                int aindex = 0;
                sBuilder.Append("<tr style='font-size:14px; white-space: nowrap;'>");
                for (int i = 0; i < iDayCount * 3 + 8 - 2; i++)
                {
                    int ii = i + 2;
                    sBuilder.Append("<td style='text-align:right;'>" + item[ii].ToString() + "</td>");
                    if (ii > 6)
                    {
                        if (ii % 3 == 2)
                        {
                            aindex = ii - (8 + (ni * 2));
                            aday[aindex] += Convert.ToDecimal(item[ii]);
                            ni++;
                        }
                    }
                }
                sBuilder.Append("</tr>");
            }
            sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            for (int i = 0; i < iDayCount; i++)
            {
                sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
                sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
                sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[i].ToString() + "</td>");
            }
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[0].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[1].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[2].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[3].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[4].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[5].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[6].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[7].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[8].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[9].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[10].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[11].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[12].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[13].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[14].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[15].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[16].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[17].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[18].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[19].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[20].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[20].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[21].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[22].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[23].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[24].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[25].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[26].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[27].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[28].ToString() + "</td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            //sBuilder.Append("<td style='text-align:center; font-size:14px; '>" + aday[29].ToString() + "</td>");
            sBuilder.Append("<td style='text-align:center; font-size:14px; '></td>");
            decimal sumde = 0.00M;
            foreach (decimal de in aday)
            {
                sumde += de;
            }
            sBuilder.Append("<td style='text-align:center; font-size:14px;'>" + sumde.ToString() + "</td>");
            sBuilder.Append("</tr>"); //style='vnd.ms-excel.numberformat:@'  
            sBuilder.Append("</table>");
            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "MaterialTongJi";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }

        /// <summary>
        /// 获取班次
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetGroup()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            GroupInfo ginfo = new GroupInfo(true);
            IList<GroupInfo> grouplist = ginfo.SelGroupInfo(100, 1, "");
            foreach (GroupInfo gi in grouplist)
            {
                dic.Add(gi.ID, gi.Group_Name);
            }
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }
        /// <summary>
        /// 获取仓库列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetWarehouse()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            WarehouseInfo wareinfo = new WarehouseInfo(true);
            IList<WarehouseInfo> warelist = wareinfo.SelWarehouseInfo(100, 1, "");
            foreach (WarehouseInfo wi in warelist)
            {
                dic.Add(wi.ID, wi.Warehouse_Name);
            }
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }
        /// <summary>
        /// 获取食堂列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetYaxNode()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            YaxNodeInfo yaxinfo = new YaxNodeInfo(true);
            IList<YaxNodeInfo> yaxlist = yaxinfo.SelYaxNodeInfo("and CONFLAG=1");
            foreach (YaxNodeInfo yaxnode in yaxlist)
            {
                dic.Add(yaxnode.NodeID, yaxnode.Nodename);
            }
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }

        //==================================================================================

    }
}
